﻿using Microsoft.AspNetCore.Mvc;
using ZilLion.Service.Core.Infrastructure.Base;

namespace ZilLion.Service.WeChatMall.Controllers
{
    public class WechatMallControllerBase : ZilLionControllerBase
    {
        /// <summary>
        ///     获取Token
        /// </summary>
        /// <returns></returns>
        protected long GetCustId()
        {
            return !GetJwtDictionary().TryGetValue("currentjwtcustid", out var custid) ? 0 : custid.ToLong();
        }


        protected string GetWechatToken()
        {
            return GetJwtDictionary().TryGetValue("currentjwtwechataccesstoken", out var token)
                ? token.ToString()
                : string.Empty;
        }


        /// <summary>
        ///     获取当前crmAPI
        /// </summary>
        /// <returns></returns>
        protected string GetCrmApiGetWay()
        {
            return !GetJwtDictionary().TryGetValue("currentjwtcrmapigetway", out var crmapigetway)
                ? string.Empty
                : crmapigetway.ToString();
        }

        /// <summary>
        ///     获取Token
        /// </summary>
        /// <returns></returns>
        protected string GetAppId()
        {
            return !GetJwtDictionary().TryGetValue("currentjwtappid", out var custid)
                ? string.Empty
                : custid.ToString();
        }

        /// <summary>
        ///     获取Token
        /// </summary>
        /// <returns></returns>
        protected string GetOpenId()
        {
            return !GetJwtDictionary().TryGetValue("currentjwtopenid", out var openid)
                ? string.Empty
                : openid.ToString();
        }

        /// <summary>
        ///     Passport
        /// </summary>
        /// <returns></returns>
        protected string GetPassport()
        {
            return $"{GetAppId()}|{GetOpenId()}";
        }
    }
}